import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home.vue'


Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/home"
  },{
    path: '/home',
    name: 'home',
    component: Home
  },{
    path: '/mall',
    name: 'mall',
    component: () => import('../views/mall.vue')
  },{
    path: '/live',
    name: 'live',
    component: () => import('../views/live.vue')
  },{
    path: '/user',
    name: 'user',
    component: () => import('../views/user.vue'),
    beforeEnter:(to,from,next) => {
      let userInfo = sessionStorage.getItem('loginStatus');
      if (to.path === '/login' || to.path === '/register') {		//如果当前进入页面是登录或注册就  不执行任何操作，继续进入。
          next();
      } else {//否则判断是否存在登录存储的数据，不存在就进入登录页面
          if (userInfo === null) {
              next('/login');
          } else {
              next();
          }
      }
    }
  },{
    path: '/newcategory',
    name: 'newcategory',
    meta:{
      headerflag:true
    },
    component: () => import('../components/newcategory.vue')
  },{
    path: '/shoppingCar',
    name: 'shoppingCar',
    meta:{
      headerflag:true
    },
    component: () => import('../components/shoppingCar.vue')
  },{
    path: '/Details',
    name: 'Details',
    meta:{
      headerflag:true
    },
    component: () => import('../components/Details.vue')
  },{
    path: '/confirmation',
    name: 'confirmation',
    meta:{
      headerflag:true
    },
    component: () => import('../components/confirmation.vue')
  },{
    path: '/AddressEdit',
    name: 'AddressEdit',
    meta:{
      headerflag:true
    },
    component: () => import('../components/AddressEdit.vue')
  },{
    path: '/AddressList',
    name: 'AddressList',
    meta:{
      headerflag:true
    },
    component: () => import('../components/AddressList.vue')
  },{
    path: '/pay',
    name: 'pay',
    meta:{
      headerflag:true
    },
    component: () => import('../components/pay.vue')
  },{
    path: '/order',
    name: 'order',
    meta:{
      headerflag:true
    },
    component: () => import('../components/order.vue')
  },{
    path: '/goodslist',
    name: 'goodslist',
    meta:{
      headerflag:true
    },
    component: () => import('../components/goodslist.vue')
  },{
    path: '/searchList',
    name: 'searchList',
    meta:{
      headerflag:true
    },
    component: () => import('../components/searchList.vue')
  },{
    path: '/collected',
    name: 'collected',
    meta:{
      headerflag:true
    },
    component: () => import('../components/collected.vue')
  },{
    path: '/login',
    name: 'login',
    meta:{
      headerflag:true
    },
    component: () => import('../components/login.vue')
  },{
    path: '/register',
    name: 'register',
    meta:{
      headerflag:true
    },
    component: () => import('../components/register.vue')
  },{
    path: '/footprint',
    name: 'footprint',
    meta:{
      headerflag:true
    },
    component: () => import('../components/footprint.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
